/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.pojo;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author Filipe
 */
@Entity
public class Disciplina implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column (name = "id_disciplina", unique = true, nullable = false)
    private Integer id;
    @Column
    private Integer cargaHoraria;
    @Column
    private String ementa;
    @Column
    private String nome;
    @OneToOne
    private Turma turma;
    @ManyToMany (cascade= CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    private Collection<Aluno> aluno;
    @OneToMany (cascade= CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    private Collection<Historico> historico;

    public Disciplina() {
    }

    public Disciplina(Integer cargaHoraria, String ementa, String nome, Turma turma) {
        this.cargaHoraria = cargaHoraria;
        this.ementa = ementa;
        this.nome = nome;
        this.turma = turma;
    }
    
    @OneToMany(cascade= CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE) 
    public Collection<Historico> getHistorico() {
        return historico;
    }

    public void setHistorico(Collection<Historico> historico) {
        this.historico = historico;
    }



    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCargaHoraria() {
        return cargaHoraria;
    }

    public void setCargaHoraria(Integer cargaHoraria) {
        this.cargaHoraria = cargaHoraria;
    }

    public String getEmenta() {
        return ementa;
    }

    public void setEmenta(String ementa) {
        this.ementa = ementa;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public Turma getTurma() {
        return turma;
    }

    public void setTurma(Turma turma) {
        this.turma = turma;
    }

    @ManyToMany (cascade= CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    public Collection<Aluno> getAluno() {
        return aluno;
    }

    public void setAluno(Collection<Aluno> aluno) {
        this.aluno = aluno;
    }
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Disciplina)) {
            return false;
        }
        Disciplina other = (Disciplina) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pojo.Disciplina[ id=" + id + " ]";
    }
    
}
